package org.jsola.contract.constant;

import org.jsola.core.validator.IConst;
import org.jsola.json.JsonKit;

import java.util.HashMap;
import java.util.Map;

/**
 * 附件类型
 *
 * @author JanusMix
 */
public enum AppendixType implements IConst {

    /**
     * 个人证件照
     */
    PERSONALCARD("personalCard","个人证件照"),
    /**
     * 身份证原件照片
     */
    IDCARDORIGINPHOTO("idCardOriginPhoto","身份证原件照片"),
    /**
     * 学历证明
     */
    CERTIFICATION("cartification","学历证明"),
    /**
     * 职业资格证书
     */
    PERFESSIONALQUALIFICATION("perfessionalQualification","职业资格证书"),
    /**
     * 获奖证书
     */
    REWARD("reward","获奖证书"),
    /**
     * 工资银行卡
     */
    SALARYCARD("salaryCard","工资银行卡"),
    /**
     * 社会保障卡
     */
    SOCIALSECURITYCARD("socialSecurityCard","社会保障卡"),
    /**
     * 公积金
     */
    ACCUMULATION("accumulation","公积金"),
    /**
     * 身份证复印件
     */
    IDCARDCOPY("idCardCopy","身份证复印件"),
    /**
     * 入职体检单
     */
    PHYSICALEXAMINATION("physicalExamination","入职体检单"),
    /**
     * 社会保险转移单
     */
    SOCIALINSURANCETRANSFER("socialInsuranceTransfer","社会保险转移单"),
    /**
     * 劳动合同
     */
    LABORCONTRACT("laborContract","劳动合同"),
    /**
     * 上家公司离职证明
     */
    LASTDIMISSIONPROVE("lastDimissionProve","上家公司离职证明"),
    /**
     * 入职简历
     */
    RESUME("resume","入职简历"),
    /**
     * 其他
     */
    OTHER("other","其他");

    private final String value;
    private final String desc;
    /**
     * 枚举值罗列，给swagger接口文档展示用
     */
    public static final String VALUES_STR = "personalCard,idCardOriginPhoto,cartification,perfessionalQualification,reward,salaryCard,socialSecurityCard,accumulation,idCardCopy,physicalExamination,socialInsuranceTransfer,laborContract,lastDimissionProve,resume,other";

     /**
     * 缓存所有value
     */
    private static final Map<String, AppendixType> LOOKUP = new HashMap<>();

    static {
        for (AppendixType e : AppendixType.values()) {
            LOOKUP.put(e.value, e);
        }
    }


    AppendixType(String value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    /**
     * 根据value查找AppendixType
     * @param value value
     * @return AppendixType
     */
    public static AppendixType find(String value) {
        return LOOKUP.get(value);
    }

    /**
     * 根据desc查找AppendixType
     * @param desc desc
     * @return AppendixType
     */
    public static AppendixType findByDesc(String desc){
        for (AppendixType e : AppendixType.values()) {
            if(e.getDesc().equals(desc)){
                return e;
            }
        }
        return null;
    }

    /**
     * 所有枚举转json
     * @return json
     */
    public static String getAllToJson() {
        Map<String,Object> map = new HashMap<>();
        for (AppendixType e : AppendixType.values()) {
            map.put("value", e.value);
            map.put("desc", e.desc);
        }
        return JsonKit.toJSONString(map);
    }

    @Override
    public boolean check(Object obj) {
        String value = (String) obj;
        return find(value) != null;
    }

    public String getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }
}
